package com.asen.alibaba.service;

import com.asen.alibaba.entity.User;
import com.asen.alibaba.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @ClassName UserService
 * @Deacription TODO
 * @Author chenxin
 * @Date 2021/3/17 22:05
 **/
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    /*查询所有*/
    public List<User> list() {
        return userMapper.selectList(null);
    }

    /*保存更新*/
    public int save(User user) {
        /*判断用户编号是否存在不存在*/
        if (StringUtils.isEmpty(user.getId())) {
            /*新增*/
            return userMapper.insert(user);
        } else {
            /*更新*/
            return userMapper.update(user, null);
        }
    }

    /*根据编号获取*/
    public User getById(String id) {
        return userMapper.selectById(id);
    }

}
